home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 90 / CD Actual 90.iso / Software3D / K-3D / k3d-0.4.2.1 / shaders / k3d_saturnring.sl < prev    next >
Encoding:
Text File  |  2004-07-23  |  3.0 KB  |  111 lines

  1. /*
  2.  * TLRing.sl -- surface for a saturn like ring to be used on a disk
  3.  *
  4.  * DESCRIPTION:
  5.  *    When put on a disk will give a "saturn-like ringed" apearence with
  6.  * varing colors and transparency.
  7.  *
  8.  * PARAMETERS:
  9.  *    Ka, Kd - the usual
  10.  *    cutoff - what point to start rings (radius of transparency)
  11.  *    ringrad - radius of ring
  12.  *    opacity - the opacity of the rings (may not be used anymore)
  13.  *
  14.  * HINTS:
  15.  *    The default values assume that the disk has a radius of one.  If it is
  16.  *  otherwise then they will neeb to be changed.
  17.  *
  18.  * AUTHOR: Tal Lancaster
  19.  *    tal@SpamSucks_cs.caltech.edu
  20.  *
  21.  * History:
  22.  *    Created: 5/15/95
  23.  */
  24.  
  25. #define RING1 0.83    /* Relative spacing for outermost ring */
  26. #define RING2 0.77    /* Relative spacing for next outermost ring */    
  27. #define RING3 0.62    /* Relative spacing for   "  outermost ring */
  28. #define RING4 0.58    /* Relative spacing for   "  outermost ring */
  29. #define RING5 0.55    /* Relative spacing for   "  outermost ring */
  30.  
  31. /* Grabbed from one of Larry Gritz's many shaders */
  32. #ifdef BMRT
  33. #define snoise(x) (2 * noise(x) - 1)    
  34. #else
  35. /* prman noise has less range */
  36. #define snoise(x) (2.5 * (noise(x) - 1))
  37. #endif /* BMRT */    
  38.  
  39. surface k3d_saturnring (float Ka = 1.0, Kd = 1.0,
  40.     cutoff = 0.55, ringrad = 1.0, opacity = 0.5;)
  41. {
  42.     point PP;       /* Transformed point */
  43.     point Nf;       /* Forward facing Normalized vector of incident light */
  44.     float val;      /* length of PP */
  45.     float relpos;   /* relative position of PP on disk 
  46.                                    (a percentage distance) */
  47.     float oi = 0.0; /* Opacity holder */
  48.     color cs;        /* color holder */
  49.     color dgrey = color (.266, .266, .266);      /* A shade of dark grey */
  50.     color dyellow = color (.73, .664, .398);     /* A shade of dark yellow */
  51.     color dpink = color (.664, .465,  .465);     /* A shade of dark pink */
  52.     color mutedgreen = color (.531, .531, .398); /* A shade of muted green */
  53.     
  54.     PP = transform ("shader", P);
  55.     val= length (PP);
  56.      
  57. #define DEBUG 0
  58. #if DEBUG    
  59.     printf ("val %f ringrad %f \n",
  60.      val,  ringrad);
  61. #endif
  62.      
  63.     if (val < cutoff * ringrad) {
  64.         /* Creating an inner disk that is transparent to place the planet */
  65.         Oi = 0.0;    
  66.     }
  67.     else {
  68.         /* Create rings of varing transparency */
  69.         relpos =  val / ringrad;
  70.         oi =  (relpos + snoise (40* relpos) - floor(relpos) );
  71.         
  72. #define DEBUG2 0
  73. #if DEBUG2
  74.         printf ("oi = %f\n", oi);
  75. #endif
  76.  
  77.         /* Create some gaps of completely transparent rings */
  78.         if (oi > 1.0)
  79.             oi = 0.0;
  80.     }
  81.     
  82.     
  83.     if (oi == 0.0)
  84.         Oi = 0.0;
  85.         
  86.     else {
  87.  
  88.         if (relpos >  RING1) 
  89.             cs = dgrey;
  90.         else if (relpos >  RING2) {
  91.             /* Want transparent section */
  92.             oi = 0.0;
  93.             Oi = 0.0;
  94.         }
  95.         else if (relpos > RING3) {
  96.             cs = dyellow;    
  97.         }
  98.         else if (relpos > RING4)
  99.             cs = dpink;    
  100.         else 
  101.             cs = mutedgreen;    
  102.  
  103.         if (oi != 0.0) {
  104.             Oi = oi;
  105.             /* A Matte model */
  106.             Nf = faceforward (normalize(N), I);
  107.             Ci = Oi * (cs * (Ka*ambient() + Kd*diffuse(Nf) ));
  108.         }
  109.     }
  110. }
  111.